﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using MySql.Data.MySqlClient;

namespace DAL
{
    /// <summary>
    /// 新鲜厨商品业务
    /// </summary>
    public  class fresh_goodsDal
    {
        /// <summary>
        /// 添加明日菜单
        /// </summary>
        /// <param name="goodname"></param>
        /// <param name="goodid"></param>
        /// <param name="mid"></param>
        /// <param name="price"></param>
        /// <param name="cover"></param>
        /// <returns></returns>
        public static int Addgood(string goodname, string goodid, string mid, string price, string cover,string sell)
        {
            string sql = "insert into ms_fresh_goods(fg_merchant_id,fg_date,fg_gid,fg_goods_name,fg_cover,fg_price,fg_sell) values(@fg_merchant_id,@fg_date,@fg_gid,@fg_goods_name,@fg_cover,@fg_price,@fg_sell)";
            MySqlParameter[] values = new MySqlParameter[7];
            values[0] = new MySqlParameter("fg_merchant_id", mid);
            values[1] = new MySqlParameter("fg_date", DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
            values[2] = new MySqlParameter("fg_gid", goodid);
            values[3] = new MySqlParameter("fg_goods_name", goodname);
            values[4] = new MySqlParameter("fg_cover", cover);
            values[5] = new MySqlParameter("fg_price", price);
            values[6] = new MySqlParameter("fg_sell", sell);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 查商户明日菜单
        /// </summary>
        /// <param name="mid"></param>
        /// <returns></returns>
        public static List<ms_fresh_goods> QueryTmoow(string mid)
        {
            string sql = "SELECT * FROM ms_fresh_goods WHERE fg_merchant_id=@fg_merchant_id and fg_date = DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY)";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("fg_merchant_id", mid);
            List<ms_fresh_goods> gdlist = new List<ms_fresh_goods>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_fresh_goods gd = new ms_fresh_goods();
                gd.fg_id = rd["fg_id"].ToString();
                gd.fg_merchant_id = rd["fg_merchant_id"].ToString();
                gd.fg_date = rd["fg_date"].ToString();
                gd.fg_gid = rd["fg_gid"].ToString();
                gd.fg_goods_name = rd["fg_goods_name"].ToString();
                gd.fg_cover = rd["fg_cover"].ToString();
                gd.fg_price = rd["fg_price"].ToString();
                gd.fg_sell = rd["fg_sell"].ToString();
                gdlist.Add(gd);
            }
            rd.Close();
            return gdlist;
        }
        /// <summary>
        /// 删除商品
        /// </summary>
        /// <param name="fgid"></param>
        /// <returns></returns>
        public static int Delgood(string fgid)
        {
            string sql = "delete from ms_fresh_goods where fg_id=@fg_id";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("fg_id", fgid);
            return DBHelper.ExcutUpdate(sql, values);
        }
    }
}
